package com.flower.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.flower.mapper.IUserDao;
import com.flower.pojo.User;
import com.flower.service.IUserService;
import com.flower.util.Md5Util;


@Service("userService")
public class UserServiceImpl implements IUserService {

    @Resource(name = "IUserDao")
    private IUserDao iUserDao;

    @Transactional
    @Override
    public int register(User user) throws Exception {
        // 获取明文密码
        String password = user.getPassword();
        // 使用工具类加密
        String passwordMd5 = Md5Util.encodeByMd5(password);
        // 将加密后的密码封装到User类中
        user.setPassword(passwordMd5);
        // 调用业务层
        return iUserDao.register(user);
    }

    // 查询操作不需要业务支持
    @Override
    public User login(User user) throws Exception {
        // 获取明文密码
        String password = user.getPassword();
        // 使用工具类加密
        String passwordMd5 = Md5Util.encodeByMd5(password);
        // 将加密后的密码封装到User类中
        user.setPassword(passwordMd5);
        // 调用业务层
        return iUserDao.login(user);
    }

	@Override
	public List<User> findAllUsers() {
		List<User> users = iUserDao.findAllUsers();
		return users;
	}

	@Override
	public int updateCount(int count, int uid) {
		return iUserDao.updateCount(count, uid);
	}

}
